<?php
class Router {
	public function go($component=null) {
		get($this->_getPath($component));
		exit;
	}
	
	private function _getPath($component=null) {
		
		if ($component == null)
			$component = isset($_GET['c']) ? $_GET['c'] : '';
		
		if ($this->_component_exists($component))
			return 'components/' . $component;
			
		get('core.Error');
		
		Error::raise(Error::$E_FATAL, 404.1);
		
	}
	
	private function _component_exists($component) {
		
		if (empty($component)) return true;
		
		$base = getBaseInclude();
		
		if (is_dir($base . DS . 'application' . DS . 'components' . DS . $component))
			return true;
		
		return false;
	}
}